//
//  BCShopDetailView.m
//  BangcaiBuy
//
//  Created by lsy on 16/6/20.
//  Copyright © 2016年 BCB. All rights reserved.
//

#import "BCShopDetailView.h"
#import "BCShopDetailCell.h"
#import "BCOderDetailAlert.h"

@interface BCShopDetailView ()<UITableViewDelegate, UITableViewDataSource>
{
    NSInteger chooseOne;
}
@property(nonnull, strong)UITableView *table;
@end

@implementation BCShopDetailView

- (void)createView
{
    self.table = [[UITableView alloc] initWithFrame:self.frame style:UITableViewStylePlain];
    self.table.rowHeight = 85.0;
    self.table.delegate = self;
    self.table.dataSource = self;
    [self addSubview:self.table];
    chooseOne = 0;
    [self.table registerClass:[BCShopDetailCell class] forCellReuseIdentifier:@"reuse"];
    self.table.separatorStyle = UITableViewCellSeparatorStyleNone;

}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 10;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    BCAlertView *alert = [[BCAlertView alloc] init];
    BCOderDetailAlert *contentView = [[BCOderDetailAlert alloc] init];
    alert.contentView = contentView;
    contentView.layer.cornerRadius = 10;
    [contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(120);
        make.bottom.mas_equalTo(-85);
        make.left.mas_equalTo(50);
        make.right.mas_equalTo(-50);
        
    }];
    [alert show];
}

- (void)choose:(UIButton *)button{
    button.selected = YES;
    chooseOne = button.tag - 1000;
    [self.table reloadData];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    BCShopDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuse"];
    cell.shopName = @"大连肉联批发市场";
    cell.shopImg = [UIImage imageNamed:@"肉"];
    cell.price = 135;
    cell.star.score = 10;
    cell.star.startColor = [UIColor colorWithRed:0.999  green:0.726  blue:0 alpha:1];
    [cell.checkBox addTarget:self action:@selector(choose:) forControlEvents:UIControlEventTouchUpInside];
    [cell.checkBox setTag:1000 + indexPath.row];
    if (indexPath.row == chooseOne) {
        cell.checkBox.selected = YES;
    }else{
        cell.checkBox.selected = NO;

    }
    return cell;
    

}


@end
